package com.opal.system.service.impl;

import com.opal.system.entity.OpalDict;
import com.opal.system.mapper.mysql.OpalDictMapper;
import com.opal.system.service.OpalDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * opal词典
 */
@Service
public class OpalDictServiceImpl implements OpalDictService {
    /**
     * 数据
     */
    private List<OpalDict> opalDicts;

    @Autowired
    private OpalDictMapper opalDictMapper;

    //根据词典pid获取相应的词典
    public List<OpalDict> getOpalDictsByPid(Integer id){
        if (opalDicts !=null && opalDicts.size()>0){
          return   opalDicts.stream().filter((a)->a.getPid()==id).collect(Collectors.toList());
        }
        return null;
    }

    public void   OpalDictServiceImplInit(){
        this.opalDicts= opalDictMapper.selectOpalDict();
    }

    public List<OpalDict> getOpalDicts() {
        return opalDicts;
    }
}
